﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Spanner;

namespace SpannerWebSite
{
    internal partial class RefStrings : Reference
    {
        internal static SpannerChapter TheChapter;

        static RefStrings()
        {
            var sections = new List<SpannerSection> { };
            var initActs = new List<Act> { };

            Action<string, string, Html> addSection = (title, id, html) =>
            {
                sections.Add(Section(Esc(title), id, html));
            };

            addSection("Ith", "Ith", P(Code("Ith(s, i)"), " denotes the JavaScript ",
                Code("s[i]"), "."));

            addSection("CharAt", "CharAt", P(Code("CharAt(s, i)"), " denotes the JavaScript ",
                Code("s.charAt(i)"), "."));

            addSection("CharCodeAt", "CharCodeAt", P(Code("CharCodeAt(s, i)"), " denotes the JavaScript ",
                Code("s.charCodeAt(i)"), "."));

            addSection("Concat", "Concat", P(Code("Concat(s1, s2, ..., sN)"), " denotes the JavaScript ",
                Code("\"\".concat(s1, s2, ..., sN)"), "."));

            addSection("FromCharCode", "FromCharCode", P(Code("FromCharCode(x)"), " denotes the JavaScript ",
                Code("String.fromCharCode(x)"), "."));

            addSection("IndexOf", "IndexOf", P(Code("IndexOf(s1, s2[, fromIndex])"), " denotes the JavaScript ",
                Code("s1.indexOf(s2, fromIndex)"), " -- the fromIndex parameter being optional."));

            addSection("LastIndexOf", "LastIndexOf", P(Code("LastIndexOf(s1, s2[, fromIndex])"), " denotes the JavaScript ",
                Code("s1.lastIndexOf(s2, fromIndex)"), " -- the ", Code("fromIndex"), " parameter being optional."));

            addSection("LocaleCompare", "LocaleCompare", P(Code("LocaleCompare(s1, s2)"), " denotes the JavaScript ",
                Code("s1.localeCompare(s2)"), "."));

            addSection("Length", "Length", P(Code("Length(s)"), " denotes the JavaScript ",
                Code("s.length"), "."));

            addSection("Match", "Match", P(Code("Match(s, x)"), " denotes the JavaScript ",
                Code("s.match(x)"), " where ", Code("x"), " may be either a string or a regular expression."));

            addSection("Replace", "Replace", P(Code("Replace(s, x, y)"), " denotes the JavaScript ",
                Code("s.Match(x)"), " where ", Code("x"), " may be either a string or a regular expression ",
                "and ", Code("y"), " may be a string or a replacement function."));

            addSection("Search", "Search", P(Code("Search(s, x)"), " denotes the JavaScript ",
                Code("s.search(x)"), " where ", Code("x"), " may be either a string or a regular expression."));

            addSection("Slice", "Slice", P(Code("Slice(s, beginSlice[, endSlice])"), " denotes the JavaScript ",
                Code("s.slice(beginSlice, endSlice)"), " -- the ", Code("endSlice"), " parameter being optional."));

            addSection("Split", "Split", P(Code("Split(s, sep[, maxResults])"), " denotes the JavaScript ",
                Code("s.split(sep, maxResults)"), " -- the ", Code("maxResults"), " parameter being optional."));

            addSection("Substr", "Substr", P(Code("Substr(s, start[, length])"), " denotes the JavaScript ",
                Code("s.substr(start, length)"), " -- the ", Code("length"), " parameter being optional."));

            addSection("Substring", "Substring", P(Code("Substring(s, start[, top])"), " denotes the JavaScript ",
                Code("s.substring(start, top)"), " -- the ", Code("top"), " parameter being optional."));

            addSection("ToDouble", "ToDouble", P(Code("ToDouble(s)"), " denotes the JavaScript ",
                Code("+s"), "."));

            addSection("ToInt", "ToInt", P(Code("ToInt(s)"), " denotes the JavaScript ",
                Code("+s"), "."));

            addSection("ToLocaleLowerCase", "ToLocaleLowerCase", P(Code("ToLocaleLowerCase(s)"), " denotes the JavaScript ",
                Code("s.toLocaleLowerCase()"), "."));

            addSection("ToLocaleUpperCase", "ToLocaleUpperCase", P(Code("ToLocaleUpperCase(s)"), " denotes the JavaScript ",
                Code("s.toLocaleUpperCase()"), "."));

            addSection("ToLowerCase", "ToLowerCase", P(Code("ToLowerCase(s)"), " denotes the JavaScript ",
                Code("s.toLowerCase()"), "."));

            addSection("ToUpperCase", "ToUpperCase", P(Code("ToUpperCase(s)"), " denotes the JavaScript ",
                Code("s.toUpperCase()"), "."));

            addSection("Trim", "Trim", P(Code("Trim(s)"), " denotes the JavaScript ",
                Code("s.trim()"), "."));

            TheChapter = CommonUI.Chapter("Reference - Strings", "RefStrings", sections, initActs);
        }
    }
}
